package com.zfdang.touchhelper.tool;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Aivin
 * created on 2023/11/10
 * des:
 */
public class LyAppTool {

    /**
     * 获取设备上安装的所有APP的包名
     */
    public static List<String> getAllAppPackageName(Context context) {
        PackageManager packageManager = context.getPackageManager();
        List<String> packageNameList = new ArrayList<>();
        Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
        List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent, PackageManager.MATCH_ALL);
        for (ResolveInfo resolveInfo : resolveInfoList) {
            packageNameList.add(resolveInfo.activityInfo.packageName);
        }
        return packageNameList;
    }
}
